package cn.zhangjie.pet.controller;

import cn.zhangjie.basic.util.JsonResult;
import cn.zhangjie.basic.util.PageList;
import cn.zhangjie.pet.domain.SearchMasterMsgAuditLog;
import cn.zhangjie.pet.query.SearchMasterMsgAuditLogQuery;
import cn.zhangjie.pet.service.ISearchMasterMsgAuditLogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (SearchMasterMsgAuditLog)表控制层
 *
 * @author makejava
 * @since 2022-08-09 17:19:14
 */
@RestController
@RequestMapping("/searchMasterMsgAuditLog")
public class SearchMasterMsgAuditLogController {
    /**
     * 注入对象
     */
    @Autowired
    private ISearchMasterMsgAuditLogService searchMasterMsgAuditLogService;

    /**
     * 分页查询
     * @return 查询结果
     */
    @PostMapping
    @ApiOperation(value = "分页查询接口")
    public PageList<SearchMasterMsgAuditLog> queryPage(@RequestBody SearchMasterMsgAuditLogQuery query) {
	try {
		return searchMasterMsgAuditLogService.queryPage(query);
	} catch (Exception e) {
		e.printStackTrace();
        return new PageList<>();
	    }
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @ApiOperation(value = "根据id查询")
    public SearchMasterMsgAuditLog findOne(@PathVariable("id") Long id) {
	    return searchMasterMsgAuditLogService.findById(id);
    }

    /**
     * 查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping()
    @ApiOperation(value = "查询所有")
    public List<SearchMasterMsgAuditLog> findAll() {
	    return searchMasterMsgAuditLogService.findAll();
    }

    /**
     * 新增or修改数据
     *
     * @param searchMasterMsgAuditLog 实体
     * @return 新增or修改结果
     */
    @PutMapping
    @ApiOperation(value = "添加or修改")
    public JsonResult addOrUpdate(@RequestBody SearchMasterMsgAuditLog searchMasterMsgAuditLog) {
        try {
		if(searchMasterMsgAuditLog.getId() == null){
			//添加操作
			searchMasterMsgAuditLogService.add(searchMasterMsgAuditLog);
		} else {
			//修改操作
			searchMasterMsgAuditLogService.update(searchMasterMsgAuditLog);
		}
		return JsonResult.me();
	} catch (Exception e) {
		e.printStackTrace();
        return JsonResult.me().setMsg("添加or修改失败");
	    }
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除")
    public JsonResult remove(@PathVariable("id") Long id) {
        try {
		searchMasterMsgAuditLogService.del(id);
		return JsonResult.me();
	} catch (Exception e) {
		e.printStackTrace();
        return JsonResult.me().setMsg("网络异常,稍后重试");
	    }
    }

    /**
     * 批量删除
     *
     * @param ids 主键
     * @return 删除是否成功
     */
    @PatchMapping
    @ApiOperation(value = "批量删除")
    public JsonResult patchDel(@RequestBody List<Long> ids) {
        try {
		searchMasterMsgAuditLogService.pactchdel(ids);
		return JsonResult.me();
	} catch (Exception e) {
		e.printStackTrace();
        return JsonResult.me().setMsg("网络异常,稍后重试");
	    }
    }

    /**
     * 无限极接口  树
     *
     * @return 获取是否成功
     */
    @GetMapping("/deptTree")
    @ApiOperation(value = "无限极接口")
    public List<SearchMasterMsgAuditLog> deptTree() {
       return searchMasterMsgAuditLogService.deptTree();
    }

}

